﻿<%@ Page Title="销售数据" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
    <link href="../assets/css/shelf/base.css" rel="stylesheet">
    <link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <link href="../assets/img/validate/validate.css" rel="stylesheet">
    <link href="../assets/css/plugins/bootstrap-datepicker/bootstrap-datepicker.min.css" rel="stylesheet" />
    <link href="../assets/css/enterpriseLayout/makePlan.css" rel="stylesheet" />
    <style type="text/css">
        .condition {
            padding: 0px;
        }

        .st-top {
            padding-top: 5px;
        }

        .st-left {
            padding-left: 20px;
        }

        .condition .tableType {
            margin: 11px 0 0 20px;
            cursor: pointer;
        }

        .condition span {
            position: relative;
            top: -2px;
            cursor: pointer;
        }

        .condition .form-control {
            height: 30px;
            padding: 0 12px;
        }

        .loadTable {
            border-bottom: 1px solid #dfdfdd;
            border-left: 1px solid #dfdfdd;
        }

            .loadTable th, .loadTable td {
                border-top: 1px solid #dfdfdd !important;
                border-right: 1px solid #dfdfdd;
                text-align: center;
            }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
    <div class="system-box">
        <div class="right-side">
            <div class="btns-container">
            </div>
            <div class="condition st-top st-left">
                <label>合同日期：</label>
                <input type="text" class="form-control input-w155 layer-date" id="ht-Begin" readonly="readonly" placeholder="合同开始日期" />
                <label>至</label>
                <input type="text" class="form-control input-w155 layer-date" id="ht-End" readonly="readonly" placeholder="合同结束日期" />
                <label>店铺：</label>
                <input class="form-control input-w155" id="search-Shop" placeholder="店铺" />

            </div>
            <div class="condition conditionS st-left">
                <label>品&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 牌：</label>
                <select class="form-control input-w110" id="search-CompanyID">
                    <option value="KM">KM</option>
                </select>
                <div style="float: left; width: 200px;">
                    <input type="radio" name="tableType" class="tableType" checked="checked" />
                    <span class="">销售日期</span>
                    <input type="radio" name="tableType" class="tableType" />
                    <span class="">会计期间</span>
                </div>
                <div id="dv-saleDate" style="float: left;">
                    <input class="form-control input-w155 layer-date" id="sale-Begin" readonly="readonly" placeholder="销售开始日期" />
                    <label>至</label>
                    <input class="form-control input-w155 layer-date" id="sale-End" readonly="readonly" placeholder="销售结束日期" />
                </div>
                <div id="dv-htDate" style="float: left; display: none;">
                    <input class="form-control input-w155 layer-date" id="balance-Date" readonly="readonly" placeholder="会计期间" />
                </div>
            </div>
            <div class="right-content-box">
                <div class="ibox-content">
                    <table class="footable table table-stripped table-list loadTable">
                        <thead></thead>
                        <tbody id="pageList"></tbody>
                    </table>
                </div>
            </div>
            <div class="pageControl"></div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>
    <script src="../assets/js/plugins/layer/laydate/laydate.js"></script>
    <script src="../assets/js/plugins/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
    <script>

        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                rScroll();
            });
            //初始化日期控件
            var start = {
                elem: "#search-start",
                format: "YYYY-MM-DD",
                istime: false,
                istoday: true,
            };
            laydate({ elem: "#ht-Begin", format: "YYYY-MM-DD", istime: false, istoday: true });
            laydate({ elem: "#ht-End", format: "YYYY-MM-DD", istime: false, istoday: true });
            laydate({ elem: "#sale-Begin", format: "YYYY-MM-DD", istime: false, istoday: true });
            laydate({ elem: "#sale-End", format: "YYYY-MM-DD", istime: false, istoday: true });
            //laydate({ elem: "#balance-Date", format: "YYYY-MM", istime: false, istoday: true});
            $('#balance-Date').datepicker({ format: "yyyy-mm", startView: 1, minViewMode: 1, language: "zh-CN", autoclose: true });
            var DateType = 0;
            $('.condition .tableType').click(function () {
                var tempIndex = $('.condition .tableType').index(this);
                DateType = tempIndex;
                if (tempIndex == 0) {
                    $("#dv-saleDate").show();
                    $("#dv-htDate").hide();

                } else {
                    $("#dv-saleDate").hide();
                    $("#dv-htDate").show();
                }
            })

            //处理表头
            if ($('.footable thead').children().size() == 0) {
                tableControl.initThead('.footable',
                [
                    {
                        trClass: '',
                        children: [
                            //{ tdText: '公司代码', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            //{ tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">序号</span>', tdId: '', tdClass: '' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">销售日期</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">店铺名称</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">类别</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">系列</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">款号</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">数量</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">单价</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">零售金额</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">明细让利</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">一般让利</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">会员让利</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">赠送分摊</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">积分抵现</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">礼券让利分摊</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">储值卡让利分摊</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">四舍五入让利分摊</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">结算金额</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">业绩金额</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">会员红利</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">其他收入分摊</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">其他收入让利分摊</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">商场对账扣减优惠券金额</span>', tdId: '', tdClass: 'diy-td-w120' },
                            { tdText: '', c: 0, r: 0, tdHtml: '<span style="display:inline-block; width:120px;">会员优惠券分</span>', tdId: '', tdClass: 'diy-td-w120' }
                        ]
                    }
                ]);
            }
            //获取浏览器类型
            var sUserAgent = navigator.userAgent.toLowerCase();
            //计算容器大小
            var calcContainer = function () {
                //计算表格高度
                $('.footable').height(
                    $('.right-side').height() - $('.conditions').outerHeight() - $('.loadTable').outerHeight() - (sUserAgent.indexOf('chrome') > -1 ? 70 : 79));
                //计算表格宽度
                $('.loadTable').width($('.footable').width());
            }
            calcContainer();
            $(window).resize(function () {
                //重新计算容器高度
                calcContainer();
            })
            var pageList = [];
            var loadList = function () {
                var ht_Begin = $("#ht-Begin").val();
                var ht_End = $("#ht-End").val();
                var shopStr = $("#search-Shop").val();
                var company = $("#search-CompanyID").val();
                var sale_Begin = $("#sale-Begin").val();
                var sale_End = $("#sale-End").val();
                var balanceDate = $("#balance-Date").val();

                pageControl.init('SaleQuery', 'CrsdPosSale', {
                    Page: page,
                    Size: 100,
                    HtBeginDate: ht_Begin,
                    HtEndDate: ht_End,
                    ShopStr: shopStr,
                    CompanyID: company,
                    SaleBeginDate: sale_Begin,
                    SaleEndDate: sale_End,
                    BalanceDate: balanceDate,
                    DateType: DateType,
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#pageList').empty();
                    }
                }, function (result) {
                    pageList = [];
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            result.data.Items.map(function (item, i) {
                                pageList.push(item);

                                console.log(item);

                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                    children: [
                                        { tdText: (item.CompanyID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide CompanyID' },
                                        { tdText: (item.Billdate || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Billdate' },
                                        { tdText: (item.ShopName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShopName' },
                                        { tdText: (item.KindName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'KindName' },
                                        { tdText: (item.SeriesName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'SeriesName' },
                                        { tdText: (item.MaterialID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'MaterialID' },
                                        { tdText: (item.Qty || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Qty' },
                                        { tdText: (item.RetailPrice || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RetailPrice' },
                                        { tdText: (item.RetailAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RetailAmount' },
                                        { tdText: (item.PresendAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Operator' },
                                        { tdText: (item.NormalPresend || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'PresendAmount' },
                                        { tdText: (item.VipPresend || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'VipPresend' },
                                        { tdText: (item.MasterPresend || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'MasterPresend' },
                                        { tdText: (item.DischargeIntegralAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'DischargeIntegralAmount' },
                                        { tdText: (item.THQPresend || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'THQPresend' },
                                        { tdText: (item.ValueCardPresend || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ValueCardPresend' },
                                        { tdText: (item.RoundAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'RoundAmount' },
                                        { tdText: (item.Amount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Amount' },
                                        { tdText: (item.Amount2 || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Amount2' },
                                        { tdText: (item.Bonus || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'Bonus' },
                                        { tdText: (item.OtherAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'OtherAmount' },
                                        { tdText: (item.OtherPresend || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'OtherPresend' },
                                        { tdText: (item.DecTHQMarkBalanceAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'DecTHQMarkBalanceAmount' },
                                        { tdText: (item.VIPCouponAmount || '0'), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'VIPCouponAmount' },
                                    ]
                                };
                                tBody.push(tempTr);
                            });
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);
                    calcContainer();
                });
            }



            //查询按钮
            $('.btns-container').on('click', '#btn-search', function () {
                page = 1;
                loadList();
            });

            //下载按钮
            $(".btns-container").on("click", '#downloadBtn', function () {
                var conditionsArr = [];
                conditionsArr.push({ column: "ht_Begin", value: $("#ht-Begin").val(), operator: "=", connector: "*" });
                conditionsArr.push({ column: "ht_End", value: $("#ht-End").val(), operator: "=", connector: "*" });
                conditionsArr.push({ column: "shopStr", value: $("#search-Shop").val(), operator: "=", connector: "*" });
                conditionsArr.push({ column: "company", value: $("#search-CompanyID").val(), operator: "=", connector: "*" });
                conditionsArr.push({ column: "sale_Begin", value: $("#sale-Begin").val(), operator: "=", connector: "*" });
                conditionsArr.push({ column: "sale_End", value: $("#sale-End").val(), operator: "=", connector: "*" });
                conditionsArr.push({ column: "balanceDate", value: $("#balance-Date").val(), operator: "=", connector: "*" });
                conditionsArr = JSON.stringify(conditionsArr);
                $.Export({
                    filetype: 'SALEQUERY',
                    filename: '销售数据',
                    conditions: encodeURIComponent(conditionsArr),
                    after: function () {
                        //回调方法
                        //loadList(1);
                        swal("导出成功!");
                    }
                });
            });
        });

    </script>
</asp:Content>

